#define _CRT_SECURE_NO_WARNINGS 1
#include<functional>
#include<mutex>
using namespace std;
class Foo
{
    mutex lock1, lock2;
public:
    Foo() {
        lock1.lock();
        lock2.lock();
    }

    void first(function<void()> printFirst)
    {

        // printFirst() outputs "first". Do not change or remove this line.
        printFirst();
        lock1.unlock();
    }

    void second(function<void()> printSecond)
    {
        lock1.lock();
        // printSecond() outputs "second". Do not change or remove this line.
        printSecond();

        lock1.unlock();

        lock2.unlock();
    }

    void third(function<void()> printThird)
    {
        lock2.lock();
        // printThird() outputs "third". Do not change or remove this line.
        printThird();

        lock2.unlock();
    }
};

class Foo
{
    mutex lock1, lock2;
public:
    Foo() {
        lock1.lock();
        lock2.lock();
    }

    void first(function<void()> printFirst)
    {

        // printFirst() outputs "first". Do not change or remove this line.
        printFirst();
        lock1.unlock();
    }

    void second(function<void()> printSecond)
    {
        lock1.lock();
        // printSecond() outputs "second". Do not change or remove this line.
        printSecond();

        lock1.unlock();

        lock2.unlock();
    }

    void third(function<void()> printThird)
    {
        lock2.lock();
        // printThird() outputs "third". Do not change or remove this line.
        printThird();

        lock2.unlock();
    }
};